import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.Random;

/**
 * @author chenshuaijun
 * @create 2023-07-26 15:21
 */
public class SelfDefineSource implements SourceFunction<String> {
    @Override
    public void run(SourceContext<String> ctx) throws Exception {
        Random random = new Random();
        while (true) {
            int value = random.nextInt(42);
            ctx.collect(value < 10 ? String.valueOf("1") : String.valueOf(value));
            Thread.sleep(100);
        }
    }

    @Override
    public void cancel() {

    }
}
